#!/bin/bash

echo "🚀 启动DNS工具..."

# 检查Docker是否运行
if ! docker info >/dev/null 2>&1; then
    echo "❌ Docker未运行，请先启动Docker"
    exit 1
fi

# 停止现有容器
echo "📋 停止现有服务..."
docker compose down 2>/dev/null

# 构建并启动服务
echo "🔨 构建并启动服务..."
docker compose up --build -d

# 等待服务启动
echo "⏳ 等待服务启动..."
sleep 3

# 检查服务状态
if curl -s http://localhost:18000/api/health >/dev/null; then
    echo "✅ DNS工具启动成功!"
    echo ""
    echo "📱 访问地址:"
    echo "   Web界面: http://localhost:18000"
    echo "   API文档: http://localhost:18000/api/health"
    echo ""
    echo "🔧 可用功能:"
    echo "   - DNS查询 (A, AAAA, CNAME, MX, TXT, NS, CAA)"
    echo "   - 域名验证 (CAA检查、CNAME链)"
    echo "   - 批量验证 (DNS TXT/CNAME/HTTP/HTTPS/FILE)"
    echo "   - WHOIS查询"
    echo ""
    echo "🐳 Docker状态:"
    docker ps --filter "name=dns-tools"
else
    echo "❌ 服务启动失败，请检查日志:"
    docker compose logs
    exit 1
fi
